import { View, Text, Picker } from "@tarojs/components";
import { AtList, AtListItem, AtButton, AtMessage } from "taro-ui";
import { useState, useEffect } from "react";
import { getDetectListbyuserApi } from "../../../utils/api";
import Taro, { useDidShow, useRouter } from "@tarojs/taro";
import { formatTime2 } from "../../../utils/to";
const detect_result = {
  1: "待完成",
  2: "正常",
  3: "蚁情",
  4: "入侵",
  5: "低电量"
};
const Index = () => {
  const router = useRouter();

  const [detailInfo, set_detailInfo] = useState({});

  useDidShow(() => {
    detectData();
  });

  // 获取探测数据
  const detectData = async () => {
    const res = await getDetectListbyuserApi({
      warn_type: 0,
      get_count: 1000,
      start_index: 0
    });
    if (res.res === 0) {
      const records = res.records;
      records.forEach(item => {
        if (item.detect_id === +router.params.id) {
          set_detailInfo(item);
        }
      });
    } else {
      Taro.atMessage({
        message: res.msg,
        type: "warning"
      });
    }
  };

  return (
    <View className="detect-detail">
      <AtListItem title="所属工程" extraText={detailInfo.project_name} />
      <AtListItem title="布点名称" extraText={detailInfo.point_name} />
      <AtListItem
        title="探测类型"
        extraText={detect_result[detailInfo.warn_type]}
      />
      <AtListItem title="分配人员" extraText={detailInfo.user_name} />
      <AtListItem
        title="探测创建时间"
        extraText={formatTime2(detailInfo.create_timestamp * 1000)}
      />
      <AtListItem
        title="探测处理时间"
        extraText={
          detailInfo.done_timestamp == 0
            ? "暂无处理"
            : formatTime2(detailInfo.done_timestamp * 1000)
        }
      />
    </View>
  );
};

export default Index;
